﻿@model IList<IceTea.Domain.Models.Product> 

@using IceTea.Domain.Models;
@using IceTea.Domain;

@{
    ViewBag.Title = "Switch Product";
    Layout = "~/Views/Shared/_Layout.cshtml";    
}

@section LeftNav{
    @Html.Partial("Product_LeftNav", IceTea.Infrastructure.ProductNav.None)
}


@if(ViewData.ModelState.IsValid == false){
<div class="col-md-10 alert alert-danger alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <ul>
  @foreach (ModelState ms in ViewData.ModelState.Values)
  {
      foreach (var error in ms.Errors)
      {
          <li>@error.ErrorMessage</li>
      }
  }</ul>
</div>}

<div class="col-md-11">
    <table class="table table-hover">
        <thead>
            <tr>
                <td class="col-md-4">Product Name</td>
                <td class="col-md-2">Joined?</td>
                <td class="col-md-2">Admin?</td>
                <td class="col-md-3">Action</td>
            </tr>
        </thead>
        <tbody>
            @foreach(Product p in Model)
            {
                  var iscurrent = ((p.Id == ((IceTeaPrincipal)User).RoleProfile.CurrentProductId));
                  var joined = ((IceTeaPrincipal)User).RoleProfile.ProductProfiles.ContainsKey(p.Id)? "Yes" : "No";
                  var admin = ((IceTeaPrincipal)User).RoleProfile.ProductProfiles.ContainsKey(p.Id) &&
                      ((IceTeaPrincipal)User).RoleProfile.ProductProfiles[p.Id].IsAdmin? "Yes" : "No";
                  var action = iscurrent? new MvcHtmlString("Current Product") : 
                      Html.ActionLink("Switch", "Choose", "Product", new { pid = p.Id }, new {@class="btn btn-default" });
                  var trclass = iscurrent ? "success" : "";
                  
                <tr class="@trclass">
                    <td>@p.Name</td>
                    <td>@joined</td>
                    <td>@admin</td>
                    <td>@action</td>
                </tr>
            }
            
        </tbody>
    </table>
</div>

